package com.liankuan.console.repository;

import com.liankuan.console.dto.UserStrategy;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserStrategyRepository extends JpaRepository<UserStrategy, Integer> {

    List<UserStrategy> findAllByUserId(int userId);

    void deleteAllByStrategyId(int id);

    void deleteAllByUserId(int userId);

    void deleteAllByUserIdAndStrategyId(int userId, int strategyId);

    UserStrategy findByUserIdAndStrategyId(int userId, int StrategyId);

    UserStrategy findByStrategyIdAndLevel(int strategyId, int level);

    @Modifying
    @Query(value = "update user_strategy set level=?1 where user_id=?2 and strategy_id=?3", nativeQuery = true)
    void updateByUserIdAndStrategyId(int level, int userId, int StrategyId);
}
